#include <stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
int abs(int a)
{
    return a > 0 ? a : -a; 
}
int main(int argc, char const *argv[])
{
    int m, n, k, list[32][32], k_count = 0, frist = 1;
    int i, j, l, max_value, max_i, max_j, result = 0;
    int lasti, lastj;

    scanf("%d%d%d", &m, &n, &k);

    for (i = 0; i < m; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%d", &list[i][j]);
        }
    }

    while (1)
    {
        max_value = -1;
        for (i = 0; i < m; i++)
        {
            for (j = 0; j < n; j++)
            {
                if (max(max_value, list[i][j]) != max_value)
                {
                    max_value = list[i][j];
                    max_i = i;
                    max_j = j;
                }
            }
        }
        if (max_value == -1)
        {
            break;
        }

        if (frist)
        {
            if (k_count + (max_i + 1) * 2 < k)
            {
                k_count += max_i + 1;
                result += list[max_i][max_j];
                list[max_i][max_j] = 0;
                lasti = max_i;
                lastj = max_j;
                frist = 0;
            }
            else 
            {
                break;
            }
            // printf("%d", k_count);
        }
        else
        {
            // printf("%d ", k_count + (abs(lastj - max_j) + abs(lasti - max_i)) + max_i);

            if ((k_count + (abs(lastj - max_j) + abs(lasti - max_i)) + max_i + 2) < k)
            {
                k_count += (abs(lastj - max_j) + abs(lasti - max_i) + 1);
                result += list[max_i][max_j];
                list[max_i][max_j] = 0;
                lasti = max_i;
                lastj = max_j;
            }
            else 
            {
                break;
            }
        }
    }
    printf("%d", result);

    return 0;
}
